﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<ComeSeeThis_MVC2.Models.GearingRecSearchResultForm>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Search Results
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2>
        FDR Calculator</h2>
    Exact Match FDR: <b>
        <%: Model.AverageFdrExact %></b> - Similar Match FDR: <b>
            <%: Model.AverageFdrSimilar %></b> Average All: <b>
                <%: Model.AverageBoth %></b>
    <br />
    <br />
    <table>
        <tr>
            <th>
                Vehicle
            </th>
            <th>
                Type
            </th>
            <th>
                Motor
            </th>
            <th>
                Voltage
            </th>
            <th>
                KiloVolt
            </th>
            <th>
                RPM
            </th>
            <th>
                FDR
            </th>
        </tr>
        <tr>
            <td>
                <% if (Model.Vehicle != null)
                   {%>
                <%:Model.Vehicle.Company.CompanyName%>
                <%:Model.Vehicle.VehicleName%>
                <% } %>
            </td>
            <td>
                <%: Model.VehicleType.VehicleTypeName %>
            </td>
            <td>
                <%:Model.Motor.Company.CompanyName %>
                <%: Model.Motor.MotorName %>
            </td>
            <td>
                <input type="text" id="voltage" name="voltage" value="<%: Model.Voltage %>" style="width: 40px" />
            </td>
            <td>
                <input type="text" id="kiloVolt" name="kiloVolt" value="<%: Model.Motor.KiloVolt %>"
                    style="width: 50px" />
            </td>
            <td>
                <input type="text" id="rpm" name="rpm" value="<% Response.Write(Model.Voltage * Model.Motor.KiloVolt); %>"
                    style="width: 50px" />
            </td>
            <td>
                <%: Model.AverageBoth %>
            </td>
        </tr>
    </table>
    <br />
    <br />
    <form id="form1" method="post" action="SearchResult.aspx">
    <input type="hidden" id="TransRatio" value="<%: Model.TransmissionRatio %>" />
    <input type="hidden" id="IdealRatio" value="<%: Model.AverageBoth %>" />
    <input type="hidden" id="SpurCount" name="SpurCount" value="<%: Model.Vehicle.VehicleSpurs.Count %>" />
    <table>
        <tr>
            <th>
                Spur
            </th>
            <th>
                Pinion
            </th>
            <th>
                Final Drive
            </th>
            <th>
                Tire
            </th>
            <th>
                Top Speed
            </th>
        </tr>
        <%
            var i = 1;
            foreach (var vehicleSpur in Model.Vehicle.VehicleSpurs)
            { %>
        <tr>
            <td>
                <input type="text" id="Vehicle_Spur<%: i %>" name="Vehicle_Spur<%: i %>" value="<%: vehicleSpur.SpurGear %>"
                    style="width: 25px" onchange="ChangePinion((<%: i %>, 0)" />
            </td>
            <td>
                <input type="button" id="Pinion<%: i %>Dec" name="Pinion<%: i %>Dec" onclick="ChangePinion(<%: i %>, 'down')"
                    value=" - " />
                <input type="text" id="Pinion<%: i %>" style="width: 25px" onchange="ChangePinion(<%: i %>, 0)" />
                <input type="button" id="Pinion<%: i %>Inc" name="Pinion<%: i %>Inc" onclick="ChangePinion(<%: i %>, 'up')"
                    value=" + " />
            </td>
            <td>
                <label id="FDR<%: i %>">
                </label>
            </td>
            <td>
                <select id="tire<%:i %>" name="<%:i %>" onchange="ChangeTire(<%:i %>)">
                    <% foreach (var tire in Model.Tires)
                       { %>
                    <option value="<%: tire.TireDiameter %>">
                        <%:tire.TireName %></option>
                    <% } %>
                </select>
                <input type="text" id="tireDiameter<%: i %>" name="tireDiameter<%: i %>" style="width: 50px" />
            </td>
            <td>
                <%--
                <input type="text" id="mphTopSpeed<%: i %>" name="mphTopSpeed<%: i %>" style="width: 40px" />mph
                <input type="text" id="kphTopSpeed<%: i %>" name="kphTopSpeed<%: i %>" style="width: 40px" />km/h
                --%>
                <span id="mphTopSpeed2<%: i %>" style="font-weight: bold"></span>mph or <span id="kphTopSpeed2<%: i %>"
                    style="font-weight: bold"></span>km/h
            </td>
        </tr>
        <% i++;
            }   %>
    </table>
    </form>
    <h2>
        Search Results</h2>
    <table>
        <tr>
            <th>
                Vehicle
            </th>
            <th>
                Vehicle Type
            </th>
            <th>
                Motor
            </th>
            <th>
                Pinion
            </th>
            <th>
                Spur
            </th>
            <th>
                FDR
            </th>
            <th>
                Track Size
            </th>
            <th>
                Track Surface
            </th>
            <th>
                Voltage
            </th>
            <th>
                Motor Temps
            </th>
            <th>
                Motor Timing
            </th>
            <th>
                Esc Timing Advance
            </th>
            <th>
                Notes
            </th>
        </tr>
        <%
            foreach (var item in Model.GearingRecs)
            {
                string style;
                if (item.MotorId == Model.Motor.MotorId && item.VehicleId != null)
                {
                    style = "ExactMatch";
                }
                else
                {
                    style = "CloseMatch";
                }
        %>
        <tr class="<%: style %>">
        <td><%: item.GearingRecId %></td>
            <td>
                <%
                    if (item.Vehicle != null) Response.Write(item.Vehicle.VehicleName);%>
            </td>
            <td>
                1/<%: item.VehicleType.Scale%> <%: item.VehicleType.VehicleTypeName %>
            </td>
            <td>
                <%: item.Motor.MotorName %>
            </td>
            <td>
                <%: item.Pinion %>
            </td>
            <td>
                <%: item.Spur %>
            </td>
            <td>
                <%: String.Format("{0:F}", item.FDR) %>
            </td>
            <td>
                <%: item.TrackSize.TrackSizeName %>
            </td>
            <td>
                <%: item.TrackSurface.TrackSurfaceName %>
            </td>
            <td>
                <%
                    Response.Write(item.CellType.CellVoltage * item.CellCount); %>
            </td>
            <td>
                <%: item.MotorTemps %>
            </td>
            <td>
                <%: item.MotorTiming %>
            </td>
            <td>
                <%: String.Format("{0:F}", item.EscTimingAdvance) %>
            </td>
            <td>
                <%: item.Notes %>
            </td>
        </tr>
        <% } %>
    </table>
    <%= Html.Telerik().ScriptRegistrar() %>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeaderContent" runat="server">
    <script src="../../Scripts/FDRCalc.js" type="text/javascript"></script>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="BodyTagContent" runat="server">
    onload="GetRatios()"
</asp:Content>
